package com.unitd.frame.mybatis.crud.builder;

/**
 * @desc 自动生成的mapper文件的sql模板和利用反射生成动态SQL的工具模板类
 * @filename SqlTemplate.java
 * @copyright www.unitd.com
 * @author Hudan
 * @version 1.0
 * @date 2017/2/7
 */
public class SqlTemplate {

	/** 条件标签 */
	public static final String IF_TAG_TEAMPLATE = "<if test=\"%s != null\">%s,</if>";
	/** 自定义脚本标签 */
	public static final String SCRIPT_TEMAPLATE = "<script>%s</script>";
	/** 需要截取的标签 */
	public static final String TRIM_PREFIX = "<trim prefix=\"(\" suffix=\")\" suffixOverrides=\",\">\n";
	public static final String TRIM_SUFFIX = "</trim>";

	/** 新增SQL */
	public static final String INSERT = "INSERT INTO %s \n %s \n VALUES \n %s";
	/** 更新SQL */
	public static final String UPDATE_BY_KEY = "UPDATE %s %s \n WHERE %s = #{%s}";

	public static String wrapIfTag(String fieldName, String expr, boolean skip) {
		if (skip) return expr;
		return String.format(IF_TAG_TEAMPLATE, fieldName, expr);
	}
}